<template>
  <div class="app-container">
    <div class="app-main">
      <div class="mainName">监测公司绑定</div>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
      >
        <!-- <el-form-item label="白蚁防治公司" prop="controlName">
          <el-input
            v-model="queryParams.controlName"
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="监测公司" prop="monitorName">
          <el-input
            v-model="queryParams.monitorName"
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >查询</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item> -->
        <el-form-item style="float: right">
          <el-button type="primary" @click="bindCompany" size="small"
            >绑定监测公司</el-button
          >
          <!-- <el-button type="primary" size="small" @click="getList()"
            >刷新设备</el-button
          > -->
          <el-button
            type="danger"
            size="small"
            @click="handleDelete"
            :disabled="!delShow"
            >删除</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        v-loading="loading"
        :data="assetList"
        border
        stripe
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="序号"
          align="center"
          type="index"
          :index="indexMethod"
        >
        </el-table-column>
        <el-table-column
          label="监测公司"
          align="center"
          prop="monitorName"
          min-width="220"
        />
        <el-table-column
          label="白蚁防治公司"
          align="center"
          prop="controlName"
          min-width="220"
        />
        <el-table-column
          label="账号"
          align="center"
          prop="accountNumber"
          min-width="220"
        />
        <el-table-column
          label="设备数量"
          align="center"
          prop="devicesNumber"
          min-width="220"
        />
        <!-- <el-table-column label="蚁害情况" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.number === '1' ? 'success' : 'danger'">
              {{ scope.row.number === "1" ? "无蚁" : "有蚁" }}
            </el-tag>
          </template>
        </el-table-column> -->

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="230"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="editDetail(scope.row)"
              >编辑
            </el-button>
            <el-button size="mini" type="text" @click="seedetail(scope.row)"
              >详情
            </el-button>
            <!-- <el-button
              size="mini"
              type="text"
              style="color: red"
              @click="unBind(scope.row)"
              >删除
            </el-button> -->
            <el-button
              size="mini"
              type="text"
              style="color: red"
              @click="handleDelete(scope.row)"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        class="pagination-container"
      />
    </div>

    <bindCompany
      v-if="bindShow"
      :show="bindShow"
      @closeMsg="closeAddMsg"
    ></bindCompany>

    <detail
      v-if="detailShow"
      :show="detailShow"
      :myTitle="myTitle"
      :itemForm="itemForm"
      :detailDis="detailDis"
      @closeMsg="closeDetail"
    ></detail>
  </div>
</template>

<script>
import {
  getMonitorCompany, // 监测公司绑定查询
  insertMonitorCompany, // 绑定监测公司数据-新增
  updateMonitorCompany, // 绑定监测公司数据-编辑
  queryMonitorCompanyData, // 监测公司查询
  monitorCompanyDataUnbind,
} from "@/api/manage/asset";
import bindCompany from "./components/bindCompany";
import detail from "./components/detail";

export default {
  name: "CompanySearch",
  dicts: [],
  components: { bindCompany, detail },
  data() {
    return {
      bindShow: false,
      detailShow: false,
      detailId: "",
      detailDis: false, // 控制是否禁用
      itemForm: {
        monitorId: "",
        monitorName: "",
        controlName: "",
        accountNumber: "",
        equipmentNum: "",
        id: "",
      },
      myTitle: "详情",
      delShow: false,
      delItemList: [],
      jcCompanyList: [],
      options: [
        {
          value: "选项1",
          label: "黄金糕",
        },
        {
          value: "选项2",
          label: "双皮奶",
        },
        {
          value: "选项3",
          label: "蚵仔煎",
        },
        {
          value: "选项4",
          label: "龙须面",
        },
        {
          value: "选项5",
          label: "北京烤鸭",
        },
      ],
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产信息表格数据
      assetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 资产分类树桩选项
      assetClassificationOptions: [],
      // 启用日期时间范围
      daterangeStartDate: [],
      // 部门树桩选项
      deptOptions: [],
      // 归属账号下拉选项
      listUsers: [
        {
          value: "行政区一",
          label: "行政区一",
        },
        {
          value: "行政区二",
          label: "行政区二",
        },
        {
          value: "行政区三",
          label: "行政区三",
        },
      ],
      // 是否显示二维码弹出层
      getCodeUrlOpen: false,
      // 打印弹出层
      openPrint: false,
      assets: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        monitorName: "",
        controlName: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // accountNumber: [
        //   { required: true, message: "资产名称不能为空", trigger: "blur" },
        // ],
      },
      // 导入结果弹出框
      resultVisible: false,
      // 人员下拉
      personnels: [],
      // 部门下拉
      departments: [],
    };
  },
  created() {
    this.getList();
    this.init();
  },
  methods: {
    init() {
      queryMonitorCompanyData().then((res) => {
        if (res.errorCode == "000000") {
          this.jcCompanyList = res.data;
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    closeAddMsg(val) {
      this.bindShow = false;
      if (val) {
        this.getList();
      }
    },
    closeDetail(val) {
      this.detailShow = false;
      if (val) {
        this.getList();
      }
    },
    // 绑定监测公司
    bindCompany() {
      this.bindShow = true;
    },
    handleSelectionChange(val) {
      console.log(val, "00000");
      this.delItemList = val.map((item) => {
        return {
          id: item.id,
        };
      });

      if (val.length > 0) {
        this.delShow = true;
      } else {
        this.delShow = false;
      }
      // this.multipleSelection = val;
    },
    indexMethod(index) {
      return index + 1;
    },
    seedetail(row) {
      console.log(row);
      this.detailId = row.id;
      this.detailShow = true;
      this.detailDis = true;
      this.myTitle = "详情";
      this.itemForm = row;
    },
    editDetail(row) {
      console.log(row, "njknjnjnjnjnjjjjjjjj");
      this.detailId = row.id;
      this.detailShow = true;
      this.detailDis = false;
      this.myTitle = "编辑";
      this.itemForm = row;
    },

    /** 二维码按钮操作 */
    getCodeUrl(row) {
      this.getCodeUrlOpen = true;
      this.title = "rfid编码（" + row.rfidCode + ")";
      // 生成二维码
      this.$nextTick(function () {
        console.log(document.getElementById("qrCodeUrl"));
        document.getElementById("qrCodeUrl").innerHTML = "";
        let qrCodeUrl = new QRCode("qrCodeUrl", {
          width: 200,
          height: 200,
          text: row.rfidCode,
          colorDark: "#000000",
          colorLight: "#fff",
        });
      });
    },
    /** 查询资产信息列表 */
    getList() {
      this.loading = true;
      getMonitorCompany(this.queryParams)
        .then((res) => {
          if (res.errorCode == "000000") {
            this.assetList = res.data.list;
            this.total = res.data.total;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      let ids = [];
      console.log(this.delItemList, row);
      this.delItemList.forEach((item) => {
        ids.push(item.id);
      });
      if (row.id) {
        ids = [row.id];
      }
      console.log(ids, "11111111");

      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return monitorCompanyDataUnbind(ids);
        })
        .then((res) => {
          console.log(res, "11");
          if (res.errorCode == "000000") {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          }
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.app-main {
  background-color: #fff;
  // padding: 15px 20px;
  border-radius: 8px;
  .mainName {
    font-family:
      PingFangSC,
      PingFang SC;
    font-weight: 500;
    font-size: 16px;
    height: 30px;
    line-height: 30px;
    color: #000000;
    border-bottom: 1px solid #dcdfe6;
    margin-bottom: 10px;
  }
  .btnGroup {
    text-align: right;
    margin: 15px 0;
  }
  .btnGroupLeft {
    text-align: left;
    margin: 15px 0;
  }
  .formBox {
    .left {
      display: inline-block;
      height: 44px;
      line-height: 44px;
      width: 100px;
      padding-right: 15px;
      border-left: 1px solid #e4e4dc;
      border-right: 1px solid #e4e4dc;
      font-family: MicrosoftYaHei;
      font-size: 12px;
      color: #303133;
      text-align: right;
      vertical-align: top;
    }
    .right {
      display: inline-block;
      width: calc(100% - 100px);
      height: 44px;
      border-right: 1px solid #e4e4dc;
      padding: 6px 15px;
      .el-select {
        width: 340px !important;
      }
      .el-input {
        width: 340px !important;
      }
    }
    .formHead {
      width: 100%;
      height: 44px;
      background-color: #5d6d7f;
      height: 44px;
      line-height: 44px;
      text-align: center;
      font-family: MicrosoftYaHei, MicrosoftYaHei;
      font-weight: bold;
      font-size: 12px;
      color: #ffffff;
    }
    .formWhite {
      width: 100%;
      height: 44px;
      background-color: #fff;
    }
    .formGray {
      width: 100%;
      height: 44px;
      background-color: #dbe2e6;
    }
  }
}
.el-collapse .el-collapse-item__header {
  font-size: 16px;
  font-weight: bold;
}

.pagination-container {
  margin-top: 20px;
  width: 100%;
}

.pagination-container .el-pagination {
  display: flex;
  justify-content: center;
  width: 100%;
}
</style>
